/**
    ATClab - scriptable Air Traffic Control simulations.
    Copyright (C) 2010 openatclab@gmail.com

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
**/

/**
 *  ATC-Lab Presentation Module
 *  Input Presentation Task.
 */

#include "inputtask.h"

#include <q3frame.h>
#include <qlayout.h>
#include <qlineedit.h>
#include <qobject.h>
//Added by qt3to4:
#include <Q3VBoxLayout>
#include <Q3BoxLayout>
#include <Q3HBoxLayout>


using namespace pact;

//------------------------------------------------------------------------------

/*!
 */
InputTask::InputTask()
	:Task()
{}

/*!
 */
InputTask::~InputTask()
{}

//------------------------------------------------------------------------------

/*!
 */
void InputTask::addWidget( QWidget *widget ) {

	Q3BoxLayout *vmgr = new Q3VBoxLayout( this );
	vmgr->addStretch();
	Q3BoxLayout *hmgr = new Q3HBoxLayout( vmgr );
	vmgr->addStretch();

	hmgr->addStretch();
	hmgr->addWidget( widget );
	hmgr->addStretch();

	connect( widget, SIGNAL( accepted() ), this, SLOT( terminate() ) );
}

/*!
 */
void InputTask::validate() {

	bool valid = true;

	foreach(QLineEdit* le, findChildren<QLineEdit*>()) {
		if ( ! le->hasAcceptableInput() ) {
			valid = false;
			le->setPaletteForegroundColor( QColor( Qt::red ) );
		} else {
			le->setPaletteForegroundColor( QColor( Qt::black ) );
		}
	}

	if ( valid ) terminate();
}

//------------------------------------------------------------------------------
